package com.hwzn.module.admin.service.impl;

import static com.hwzn.module.core.enums.ErrorCodeConstants.TEST_EX_ERROR;
import static com.hwzn.module.core.utils.ServiceExceptionUtil.exception;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import com.hwzn.module.admin.mapper.UserMapper;
import com.hwzn.module.admin.service.UserService;
import com.hwzn.module.core.dos.UserDO;
import com.hwzn.module.core.exception.ServiceException;
import com.hwzn.module.core.utils.SecurityContextUtil;

/**
 * user service
 *
 * @author jiaobo
 * @date Created in 2024/5/15 11:17
 * @company hw
 **/
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Resource
    private PasswordEncoder passwordEncoder;

    // @Value("${en.value}")
    // private String enValue;

    @Override
    public UserDO getUserById(Long id) {
        return userMapper.selectById(id);
    }

    @Override
    public UserDO getUserByUsername(String username) {
        return userMapper.selectByName(username);
    }

    @Override
    public boolean isPasswordMatch(String inPassword, String password) {
        return passwordEncoder.matches(inPassword, password);
    }

    @Override
    public void addUser(UserDO userDO) {
        userMapper.insert(userDO);
    }

    @Override
    public void test() {
        UserDO user = SecurityContextUtil.getUser();
        user.getId();
    }

}
